package com.two.service.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.two.common.entity.User;

import com.two.common.util.CommonResult;
import com.two.service.user.mapper.UserMapper;
import com.two.service.user.service.IUserService;
import com.two.service.user.vo.UserVo;
import com.two.service.user.vo.ZhuceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 汪瑞明
 * @since 2022-08-31
 */
@Service

public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public CommonResult selectUser(Integer currentPage, Integer pageSize, UserVo userVo) {
        Page<User> page = new Page<>(currentPage, pageSize);

        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(userVo.getUsermonicker())) {
            wrapper.like("usermonicker", userVo.getUsermonicker());
        }
        if (StringUtils.hasText(userVo.getPhone())) {
            wrapper.like("phone", userVo.getPhone());
        }

        Page<User> userPage = userMapper.selectPage(page, wrapper);


        System.out.println("用户"+userPage.toString());
        return new CommonResult(2000, "查询成功", userPage);
    }

    @Override
    public CommonResult insert(User user) {
        int insert = userMapper.insert(user);
        if (insert>0){
            return new CommonResult(2000,"添加成功",null);
        }
        return new CommonResult(5000,"添加失败",null);
    }

    @Override
    public int xiu(User user1) {
        return userMapper.updateById(user1);
    }


}
